package com.station.client;

import com.station.client.proxies.PCoordinates;
import com.station.client.proxies.PPetrolPump;

/**
 * Created with IntelliJ IDEA.
 * User: Jimmy87
 * Date: 12.03.14
 * Time: 18:01
 * To change this template use File | Settings | File Templates.
 */
public class Car extends SimpleCar {

    private PPetrolPump fillingPump;
    private double currentCapacity;
    private double maxCapacity;


    public Car(PCoordinates coordinates, String fuelType) {
        super(coordinates, fuelType);
        if (isProcFinished())
            setQueneNumber(100);
        maxCapacity = 100.0;
        //currentCapacity = maxCapacity * Math.random();      //todo test
        currentCapacity = 0;
    }

    public boolean isProcFinished() {
        return currentCapacity >= (int) (Base.fillCoefficient * maxCapacity);
    }

    public double getCurrentCapacity() {
        return currentCapacity;
    }

    public void increaseCurrentCapacity(double value) {
        this.currentCapacity += value;
    }

    public PPetrolPump getFillingPump() {
        return fillingPump;
    }

    public void setFillingPump(PPetrolPump fillingPump) {
        this.fillingPump = fillingPump;
        setQueneNumber(fillingPump.getNumber());
        setTarget(fillingPump.getFillingPlace());
    }

    public int getFuelDifference() {                  //todo WRONG
        return (int)(maxCapacity*Base.fillCoefficient);
    }

    @Override
    public void finishFilling(PCoordinates outPoint, PCoordinates exitPoint) {
        getFillingPump().setBusy(false);
        setState(State.Standing);
        setPriorityTarget(outPoint);
        setTarget(exitPoint);
        setQueneNumber(Base.priorityQuene);
    }
}
